#ifndef _GRAPHIC_ELEMENT_H
#define _GRAPHIC_ELEMENT_H

#include <windows.h>
#include <gdiplus.h>
//#include <string.h>
//#include <iostream>

#include "Rect2D.h"
#include "Colors.h"

//using namespace std;
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")


class GraphicElement
{
protected:
	HWND hWnd;
	Rect2D *dimensions;
	bool redraw;
	//int x, y, width, height;

	bool checkBoundingBox()
	{
		bool ret = false;
		LPPOINT p = new POINT;
		GetCursorPos(p);
		ScreenToClient(hWnd, p);


		if(p->x >= dimensions->x+1 && p->x <= dimensions->x + dimensions->width-1 &&
			p->y >= dimensions->y && p->y <= dimensions->y + dimensions->height)
		{
			//SendMessage(hWnd, WM_COMMAND, control_id, 0);
			ret = true;

		}

		delete[] p;
		return ret;
	}

public:
	GraphicElement(int x, int y, int width, int height, HWND hWnd)
	{
		this->hWnd = hWnd;
		dimensions = new Rect2D(x, y, width, height);
		this->redraw = true;
		/*this->x			= x;
		this->y			= y;
		this->width		= width;
		this->height	= height;*/
	}

	Rect2D *getDimensions()
	{
		return dimensions;
	}


	virtual void UpdateGraphics()
	{
		redraw = true;

		RECT* lpRect = new RECT;

		lpRect->top = dimensions->y;
		lpRect->left = dimensions->x; 

		lpRect-> bottom = dimensions->y+dimensions->height;
		lpRect->right = dimensions->x+dimensions->width;


		InvalidateRect(hWnd, lpRect, false);

		delete[] lpRect;

	}

	//virtual void Update() {}
	virtual void MouseDown() {}
	virtual void MouseUp() {}
	virtual void Hover() {}
	virtual void OnDblClick() {}
	virtual void Draw(HDC hdc) = 0;
};


#endif